<?php

namespace app\api\model\entity;

use app\logic\model\entity\EntityVoiceLogicModel;

class EntityVoiceApiModel extends EntityVoiceLogicModel
{
    public function getApiList(array $param, array $where=[], string $field='*', $page=1, $limit=15,string $order='sort desc')
    {
        $query=$this->where($where)
            ->where(function ($q) use ($param){
                if(check_request($param,'title')){
                    $q->whereLike("title","%{$param['title']}%");
                }
                if(check_request($param,'type_id')){
                    $q->whereIn("type_id",$param['type_id']);
                }
                if(check_request($param,'status')){
                    $q->where("status",$param['status']);
                }
            });
        $list = $query->field($field)->order($order)
            ->page($page,$limit)->select();
        $count = $query->count();
        return [$list,$count];
    }

    public function details($id, string $field='*')
    {
        $info = $this->getFindById($id,$field);
        if(empty($info)){
            return false;
        }
        return $info;
    }
}